<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="moduleTitle" :close-on-click-modal="false" class="tl-dialog"
    width="1000px" @open="open" @close="close" :append-to-body="true" :modal-append-to-body="true">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="12">
          <el-form-item label="任命类型" prop="appointmenttype" :rules="rules.validateRequire">
            <el-select v-model="model.appointmenttype" :disabled="true">
              <el-option v-for="item in codeModel.appointmenttypeList" :key="item.code" :label="item.name"
                :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="排序码" prop="sortcode">
            <el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="撤销人员姓名" prop="username" :rules="rules.validateRequire">
            <el-input v-model="model.username" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectTeamDialog">
              </el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="撤销人员工号" prop="usercode" :rules="rules.validateRequire">
            <el-input v-model="model.usercode" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="工作组名称" prop="workgroup" :rules="rules.validateRequire">
            <!-- <el-input v-model="model.workgroup" :disabled="true"></el-input> -->
            <el-input :disabled="!model.workgroup ? false : true" v-model="model.workgroup"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目角色" prop="projectrole" :rules="rules.validateRequire">
            <!-- <el-input v-model="model.projectrole" :disabled="true"></el-input> -->
            <el-select v-model="model.projectrole" filterable clearable :disabled="true">
              <el-option v-for="item in codeModel.projectroleList" :key="item.code" :label="item.name"
                :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="职责" prop="duty" :rules="rules.validateRequire">
            <el-input v-model="model.duty"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSaveAndCopy" :loading="saveLoading">保存并复制</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认
      </el-button>
    </div> -->
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认
      </el-button>
    </div>
    <tlmpmProject-team-ref ref="mpmProjectTeamRef" @confirm="getMpmProjectTeamData" :isSingleSelect="true"
      :externalQueryParam="externalQueryParamForTeam">
    </tlmpmProject-team-ref>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
import tlmpmProjectTeamRef from '@/views/gpm/gpmProjectTeam/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { tlmpmProjectTeamRef },
  data() {
    return {
      moduleTitle: '撤销任命',
      urlPrefix: '/sd/projectTeam/',
      url: {
        // 额外的url
        queryCodeList: '/sd/projectTeam/dataCodeList'
      },
      externalQueryParamForTeam: {}
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      default: ''
    },
    projectId: {
      type: [Number, String],
      default: ''
    },
    projectCode: {
      type: [Number, String],
      default: ''
    },
    teamType: {
      type: [Number],
      required: 0
    },
    preTeamType: {
      type: [String],
      required: ''
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'revokedate', new Date())
        this.$set(this.model, 'applydate', new Date())
        this.$set(this.model, 'teamid', this.teamType)
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (this.isAdd) {
        this.$set(this.model, 'projectcode', this.projectCode)
        this.$set(this.model, 'projectid', this.projectId)
        this.$set(this.model, 'appointmentid', this.parentId)
        this.$set(this.model, 'appointmenttype', '2')
        this.$set(this.model, 'teamid', this.teamType)
      }
    },
    /** 打开项目组成员参照 */
    openMpmProjectTeamDialog() {
      const { projectcode } = this.model
      this.externalQueryParamForTeam = {
        qry_projectcode: projectcode,
        qry_state: '9',
        qry_enabled: 1,
        qry_appointmenttype: '1',
        qry_teamType: this.preTeamType ? this.preTeamType : 0
      }
      this.$refs.mpmProjectTeamRef.visible = true
    },
    /** 获取项目组成员参照数据 */
    getMpmProjectTeamData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'usercode', selectionRow.usercode)
      this.$set(this.model, 'username', selectionRow.username)
      this.$set(this.model, 'workgroup', selectionRow.workgroup)
      this.$set(this.model, 'projectrole', selectionRow.projectrole)
      this.$set(this.model, 'position', selectionRow.position)
      this.$set(this.model, 'duty', selectionRow.duty)
    }
  }
}
</script>

